package cn.edu.bishi;

import java.util.Scanner;

public class 修改字符串权值 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String string = scanner.next();
        char[] chars = string.toCharArray();

        int weight = 0;
        int want = 0;
        for (int i = 1; i < chars.length; i++) {
            if (chars[i] != chars[i-1]) {
                weight++;
                if (i+1 < chars.length && chars[i-1] == chars[i+1]) want++;
            }
        }


        if (weight == 0) {
            weight = 0;
        } else if (weight == 1) {
            weight = 0;
        } else if (weight == 2){
            weight = 0;
        } else if (weight == 3) {
            weight = 0;
        } else {
            if (want >= 2) weight -= 4;
            if (want == 1) weight -= 3;
            if (want == 0) weight -= 2;
        }

        System.out.println(weight);
    }
}
